package com.easy.controller;

import com.easy.bean.ServiceStylist;
import com.easy.service.ServiceStylistService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("serviceStylist")
public class ServiceStylistController {

    @Autowired
    ServiceStylistService serviceStylistService;

    @PostMapping
    public Result add(@RequestBody ServiceStylist serviceStylist) {
        Object obj = serviceStylistService.add(serviceStylist);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody ServiceStylist serviceStylist) {
        Object obj = serviceStylistService.edit(serviceStylist);
        return Result.success("编辑信息保持成功", obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id) {
        Object obj = serviceStylistService.del(id);
        return Result.success("删除成功", obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = serviceStylistService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(ServiceStylist serviceStylist) {
        Object obj = serviceStylistService.all(serviceStylist);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, ServiceStylist serviceStylist) {
        // 查询一共有多少条数据
        // 当前页要显示的数据
        // 将以上数据封装到page对象中
        // 返回page对象
        serviceStylistService.page(page, serviceStylist);
        // 返回page对象
        return Result.success(page);
    }
}
